import java.util.Arrays;
import java.util.Comparator;

// https://leetcode-cn.com/problems/minimum-number-of-arrows-to-burst-balloons/
// 452. 用最少数量的箭引爆气球


class Solution {
    public int findMinArrowShots(int[][] points) {
        int result = 1;
        Arrays.sort(points, Comparator.comparingInt(a -> a[0]));

        for (int i = 1; i < points.length; i++) {
            if (points[i][0] > points[i - 1][1]) {
                result++;
            } else {
                points[i][1] = Math.min(points[i-1][1], points[i][1]);
            }
        }
        

        return result;
    }
}
